package Operation;

import BOOK.Book;
import BOOK.BookList;

/**
 * Creat with IntelliJ IDEA
 * Description:
 * User:WZW
 * Date:2021-11-27
 * Time:18:46
 */
public class Del implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书：");
        System.out.println("请输入要删除的图书的名字：>");
        String name = scanner.nextLine();
        int index = bookList.search(name);
        if(index==-1){
            System.out.println("没有你要删除的图书！");
            return;
        }
        int size = bookList.getUsedSize();
        for (int i = index; i <size ; i++) {
            if (i==size-1){
                bookList.setBooks(i,null);
            }
            Book book = bookList.getIndex(i+1);
            bookList.setBooks(i,book);
        }
        bookList.setUsedSize(size-1);
        System.out.println("删除成功！");
    }
}
